package cn.com.support.authentication;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.security.web.util.RequestMatcher;

import cn.com.commons.utils.StringUtil;
import cn.com.support.context.AuthenticationContext;

/**
 * 加载资源与权限的对应关系
 * 
 * @since 2012-3-9 上午1:13:20
 * @version 1.0
 * @author Microbun
 */
public class AuthenticationMetadataSource implements
		FilterInvocationSecurityMetadataSource {
	
//    private final Map<RequestMatcher, Collection<ConfigAttribute>> requestMap=null;

    @Override
	public Collection<ConfigAttribute> getAttributes(Object object)
			throws IllegalArgumentException {
//    	StringUtil.isEmpty(O);
        final String resource = ((FilterInvocation) object).getRequestUrl();
        return AuthenticationContext.getAuthentication(resource);
	}

    @Override
	public Collection<ConfigAttribute> getAllConfigAttributes() {
        return AuthenticationContext.getAllAuthentication();
	}

	@Override
	public boolean supports(Class<?> clazz) {
		 return FilterInvocation.class.isAssignableFrom(clazz);
	}


}
